package com.hz.pay.center.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {

    /**
     * 支付业务交换机
     */
    public static final String PAY_NOTIFY_TOPIC_EXCHANGE  = "pay.notify.topic.exchange";

    //支付业务队列
    public static final String PAY_NOTIFY_QUEUE = "pay.notify.queue";

    /**
     * 死信交换机
     */
    public static final String  TTL_PAY_NOTIFY_EXCHANGE = "ttl.pay.notify.exchange";


    /**
     * 死信队列
     */
    public static final String TTL_PAY_NOTIFY_QUEUE = "ttl.pay.notify.queue";



    //声明队列
    @Bean
    public Queue queue(){
        return new Queue(PAY_NOTIFY_QUEUE);
    }


    //声明交换机
    @Bean
    public TopicExchange topicExchange(){

        return new TopicExchange(PAY_NOTIFY_TOPIC_EXCHANGE);
    }



    //声明队列
    @Bean
    public Queue ttlQueue(){
        return new Queue(TTL_PAY_NOTIFY_QUEUE);
    }

    /**
     * 死信交换机 - 类型 direct
     * @return
     */
    @Bean
    public DirectExchange directExchange(){

        return new DirectExchange(TTL_PAY_NOTIFY_EXCHANGE);
    }


    @Bean
    public Binding binding(){

        return BindingBuilder.bind(queue()).to(topicExchange()).with("pay.*");
    }


    /**
     * 死信队列和死信交换机绑定
     * @return
     */
    @Bean
    public Binding deadBind(){

        return BindingBuilder.bind(ttlQueue()).to(directExchange()).with("pay.notify");
    }



}
